package registe.service;

import net.iharder.Base64;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import registe.bean.TUserInfo;
import registe.dao.TUserInfoMapper;
import registe.untill.baseUntill.Map_ObjectUntill;
import registe.untill.baseUntill.MessageUntill;
import registe.untill.baseUntill.RespCodeBody;

import java.util.Map;

/**
 * Created by zhoumeineng on 2018/1/24.
 */

@Service
public class UserInfoImpl {

    @Autowired
    TUserInfoMapper tUserInfoMapper;

    /**
     * 获取用户信息
     *
     */

    @Transactional
    public JSONObject getUserInfo(String uid){
        TUserInfo tUserInfo = tUserInfoMapper.selecteUserInfo(uid);

        System.out.printf("++++++++:"+tUserInfo.getRealname());
        Map map = null;
        try {
            map = Map_ObjectUntill.objectToMap(tUserInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return MessageUntill.messageBody(map, RespCodeBody.RESP_SUCCED_CODE.getRespCode(),RespCodeBody.RESP_SUCCED_CODE.getRespDesc());
    }


    /**
     *
     * 开通刷脸 脸部照片和身份信息插入
     *
     * */
     @Transactional
     public JSONObject updataUserInfo(TUserInfo tUserInfo){

         /**
          * 将身份证号加密
          * */
         if (tUserInfo.getIdnum()!=null){
             tUserInfo.setIdnum(Base64.encodeBytes(tUserInfo.getIdnum().getBytes()));
         }
         /**
          * 更新数据
          * */
         tUserInfoMapper.upUserInfo(tUserInfo);
         return MessageUntill.messageBody(null,RespCodeBody.RESP_SUCCED_CODE.getRespCode(),RespCodeBody.RESP_SUCCED_CODE.getRespDesc());
     }




}
